using System;
namespace ch.ethz.ssh2
{
	
	/// <summary> A <code>SFTPv3FileAttributes</code> object represents detail information
	/// about a file on the server. Not all fields may/must be present.
	/// 
	/// </summary>
	/// <author>  Christian Plattner
	/// </author>
	/// <version>  2.50, 03/15/10
	/// </version>
	
	public class SFTPv3FileAttributes
	{
		/// <summary> Checks if this entry is a directory.
		/// 
		/// </summary>
		/// <returns> Returns true if permissions are available and they indicate
		/// that this entry represents a directory.
		/// </returns>
		virtual public bool Directory
		{
			get
			{
				if (permissions == null)
					return false;
				
				return ((permissions & 16384) != 0);
			}
			
		}
		/// <summary> Checks if this entry is a regular file.
		/// 
		/// </summary>
		/// <returns> Returns true if permissions are available and they indicate
		/// that this entry represents a regular file.
		/// </returns>
		virtual public bool RegularFile
		{
			get
			{
				if (permissions == null)
					return false;
				
				return ((permissions & 32768) != 0);
			}
			
		}
		/// <summary> Checks if this entry is a a symlink.
		/// 
		/// </summary>
		/// <returns> Returns true if permissions are available and they indicate
		/// that this entry represents a symlink.
		/// </returns>
		virtual public bool Symlink
		{
			get
			{
				if (permissions == null)
					return false;
				
				return ((permissions & 40960) != 0);
			}
			
		}
		/// <summary> Turn the POSIX permissions into a 7 digit octal representation.
		/// Note: the returned value is first masked with <code>0177777</code>.
		/// 
		/// </summary>
		/// <returns> <code>NULL</code> if permissions are not available.
		/// </returns>
		virtual public System.String OctalPermissions
		{
			get
			{
				if (permissions == null)
					return null;
				
				System.String res = System.Convert.ToString((int)permissions & 65535, 8);
				
				System.Text.StringBuilder sb = new System.Text.StringBuilder();
				
				int leadingZeros = 7 - res.Length;
				
				while (leadingZeros > 0)
				{
					sb.Append('0');
					leadingZeros--;
				}
				
				sb.Append(res);
				
				return sb.ToString();
			}
		}
		/// <summary> The SIZE attribute. <code>NULL</code> if not present.</summary>
		public System.Int64? size = null;
		
		/// <summary> The UID attribute. <code>NULL</code> if not present.</summary>
		public System.Int32? uid = null;
		
		/// <summary> The GID attribute. <code>NULL</code> if not present.</summary>
		public System.Int32? gid = null;
		
		/// <summary> The POSIX permissions. <code>NULL</code> if not present.
		/// <p>
		/// Here is a list:
		/// <p>
		/// <pre>Note: these numbers are all OCTAL.
		/// 
		/// S_IFMT     0170000   bitmask for the file type bitfields
		/// S_IFSOCK   0140000   socket
		/// S_IFLNK    0120000   symbolic link
		/// S_IFREG    0100000   regular file
		/// S_IFBLK    0060000   block device
		/// S_IFDIR    0040000   directory
		/// S_IFCHR    0020000   character device
		/// S_IFIFO    0010000   fifo 
		/// S_ISUID    0004000   set UID bit
		/// S_ISGID    0002000   set GID bit 
		/// S_ISVTX    0001000   sticky bit
		/// 
		/// S_IRWXU    00700     mask for file owner permissions
		/// S_IRUSR    00400     owner has read permission
		/// S_IWUSR    00200     owner has write permission
		/// S_IXUSR    00100     owner has execute permission
		/// S_IRWXG    00070     mask for group permissions
		/// S_IRGRP    00040     group has read permission
		/// S_IWGRP    00020     group has write permission
		/// S_IXGRP    00010     group has execute permission
		/// S_IRWXO    00007     mask for permissions for others (not in group)
		/// S_IROTH    00004     others have read permission
		/// S_IWOTH    00002     others have write permisson
		/// S_IXOTH    00001     others have execute permission
		/// </pre>
		/// </summary>
		public System.Int32? permissions = null;
		
		/// <summary> The ATIME attribute. Represented as seconds from Jan 1, 1970 in UTC.
		/// <code>NULL</code> if not present.
		/// </summary>
		public System.Int32? atime = null;
		
		/// <summary> The MTIME attribute. Represented as seconds from Jan 1, 1970 in UTC.
		/// <code>NULL</code> if not present.
		/// </summary>
		public System.Int32? mtime = null;
	}
}